﻿#region Copyright (c) 2000-2013 Developer Express Inc.
/*
{*******************************************************************}
{                                                                   }
{       Developer Express .NET Component Library                    }
{                                                                   }
{                                                                   }
{       Copyright (c) 2000-2013 Developer Express Inc.              }
{       ALL RIGHTS RESERVED                                         }
{                                                                   }
{   The entire contents of this file is protected by U.S. and       }
{   International Copyright Laws. Unauthorized reproduction,        }
{   reverse-engineering, and distribution of all or any portion of  }
{   the code contained in this file is strictly prohibited and may  }
{   result in severe civil and criminal penalties and will be       }
{   prosecuted to the maximum extent possible under the law.        }
{                                                                   }
{   RESTRICTIONS                                                    }
{                                                                   }
{   THIS SOURCE CODE AND ALL RESULTING INTERMEDIATE FILES           }
{   ARE CONFIDENTIAL AND PROPRIETARY TRADE                          }
{   SECRETS OF DEVELOPER EXPRESS INC. THE REGISTERED DEVELOPER IS   }
{   LICENSED TO DISTRIBUTE THE PRODUCT AND ALL ACCOMPANYING .NET    }
{   CONTROLS AS PART OF AN EXECUTABLE PROGRAM ONLY.                 }
{                                                                   }
{   THE SOURCE CODE CONTAINED WITHIN THIS FILE AND ALL RELATED      }
{   FILES OR ANY PORTION OF ITS CONTENTS SHALL AT NO TIME BE        }
{   COPIED, TRANSFERRED, SOLD, DISTRIBUTED, OR OTHERWISE MADE       }
{   AVAILABLE TO OTHER INDIVIDUALS WITHOUT EXPRESS WRITTEN CONSENT  }
{   AND PERMISSION FROM DEVELOPER EXPRESS INC.                      }
{                                                                   }
{   CONSULT THE END USER LICENSE AGREEMENT FOR INFORMATION ON       }
{   ADDITIONAL RESTRICTIONS.                                        }
{                                                                   }
{*******************************************************************}
*/
#endregion Copyright (c) 2000-2013 Developer Express Inc.

using System;
using System.Windows;
using System.Linq;
using System.Collections.Generic;
using System.Windows.Controls;
using UCOLOR.Model;
using UCOLOR.View;
namespace UColor.WPF.Internal {
	public partial class BaseControlModulesPageView : BaseControlPartView {
		public BaseControlModulesPageView() {
			InitializeComponent();
            ShowModudel();
		}

        private void ProductTile_Click(object sender, EventArgs e)
        {
            DevExpress.Xpf.LayoutControl.TileLayoutControl tlc = ((DevExpress.Xpf.LayoutControl.Tile)sender).Parent as DevExpress.Xpf.LayoutControl.TileLayoutControl;
            if (tlc == null)
                return;
            List<UCOLOR.Model.ExhibitionGroupItem> list = tlc.ItemsSource as List<ExhibitionGroupItem>;
            string itemNo = ((DevExpress.Xpf.LayoutControl.Tile)sender).Uid;
            UCOLOR.Model.ExhibitionGroupItem item = list.Find(p => p.item_no == itemNo);
            if (item == null)
                return;
            ShowProduct(item);         
            //ShowDir(((DevExpress.Xpf.LayoutControl.Tile)sender).Uid);
        }

        private void DirTile_Click(object sender, EventArgs e)
        {
            DevExpress.Xpf.LayoutControl.TileLayoutControl tlc = ((DevExpress.Xpf.LayoutControl.Tile)sender).Parent as DevExpress.Xpf.LayoutControl.TileLayoutControl;
            if (tlc == null)
                return;
            List<UCOLOR.Model.ExhibitionGroupItem> list = tlc.ItemsSource as List<ExhibitionGroupItem>;
            string itemNo = ((DevExpress.Xpf.LayoutControl.Tile)sender).Uid;
            UCOLOR.Model.ExhibitionGroupItem item = list.Find(p => p.item_no == itemNo);
            if (item == null)
                return;
           // PartProductCode part =DataHelper.GetPartProductCode(item.product_code).First();
            ShowDir(item);
        }


        public void ShowProduct(ExhibitionGroupItem item)
        {
            BaseControlModulesPage modulePage = this.DataContext as BaseControlModulesPage;
            ProductView view = new ProductView(item.catalog_no);
            
            view.ParentModulePage = modulePage;
            modulePage.OpenModule(view);
            view.ShowProduct(1);
            //view.ShowProduct(1);
        }


        public void ShowDir(ExhibitionGroupItem item)
        {
            BaseControlModulesPage modulePage = this.DataContext as BaseControlModulesPage;

          //  DirView dir = new DirView(item, modulePage);
            HomeView dir = new HomeView(2, item.product_code, modulePage);
            dir.ParentModulePage = modulePage;
           modulePage.OpenModule(dir);
        }



        public IList<ProductCategory> data
        {
            get;
            set;
        }
        public void ShowModudel()
        {
           // data = DataHelper.getCategorys().Where(p => p.ID == 2).ToList();
            G01.ItemsSource = DataHelper.GetExhibitionGroupItem("G01");
            G02.ItemsSource = DataHelper.GetExhibitionGroupItem("G02");
            G03.ItemsSource = DataHelper.GetExhibitionGroupItem("G03");
        }

        private void Tile_Click(object sender, EventArgs e)
        {
            BaseControlModulesPage modulePage = this.DataContext as BaseControlModulesPage;
            HomeView dir = new HomeView(1,null,modulePage);
            dir.ParentModulePage = modulePage;
            modulePage.OpenModule(dir);
        }

        private void Tile_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            if (e.ClickCount == 2)
            {
               // (this.DataContext as ProductView).di
            }
        }
	}
}
